package com.escapeicon.bigevent.controller;

import com.escapeicon.bigevent.pojo.vo.ResultVO;
import com.escapeicon.bigevent.utils.AliOssUtil;
import com.escapeicon.bigevent.utils.UUIDUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
public class FileUploadController {

    @PostMapping("/upload")
    public ResultVO<String> upload(MultipartFile file) throws Exception {
        // 获取文件内容的输入流，写入本地磁盘文件
        String fileName = UUIDUtil.getUUID() + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));

        // 调用工具类给 oss 上传图片且获取 url
        String url = AliOssUtil.uploadFile(fileName, file.getInputStream());

        return ResultVO.success(url);
    }
}
